import pymysql

'''
创建数据库表
'''

# Open database connection
db = pymysql.connect("localhost", "root", "root", "py_test")

# prepare a cursor object using cursor() method
cursor = db.cursor()

# Drop table if it already exist using execute() method
cursor.execute('drop table if exists employee')

# Create table as per requirement
sql = '''CREATE TABLE `employee` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `first_name` char(20) NOT NULL,
  `last_name` char(20) DEFAULT NULL,
  `age` int(11) DEFAULT NULL,
  `sex` char(1) DEFAULT NULL,
  `income` float DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;'''

cursor.execute(sql)
print("Created table Successful.")

# disconnect from server
db.close()
